package org.example;

import cn.clj1.CljCharIterator;
import cn.clj1.CljLexer;
import cn.clj1.CljLinesFromString;
import cn.clj1.MyClojureInterp;
import cn.clj1.MyClojureReader;
import cn.clj1.cell.CljCell;
import org.junit.Test;

import java.util.Hashtable;

public class MyClojure_case {

    public static MyClojureReader getReader(String txt)
    {
        CljLinesFromString myIInput = new CljLinesFromString(txt);
        CljCharIterator myCharIterator = new CljCharIterator(myIInput);
        CljLexer lexer = new CljLexer(myCharIterator);
        MyClojureReader myLispReader = new MyClojureReader(lexer);
        return myLispReader;
    }

    @Test
    public void test_loop() throws Exception {

        MyClojureInterp myClojureInterp = new MyClojureInterp();
        MyClojureReader myLispReader = getReader("(loop [iter 1\n" +
                "       acc  0]\n" +
                "  (if (> iter 10)\n" +
                "    (println acc)\n" +
                "    (recur (+ 1 iter) (+ acc iter))))");
        CljCell myCell = myLispReader.getExpression();
        //System.out.println(myCell.toString());
        myClojureInterp.eval(myCell, new Hashtable<String, CljCell>(), null, new CljCell());
    }
}





































